﻿/*************************************************************************
 * Created by OhZee Creative, LLC
 * 2013
 * This code is licensed under Microsoft Public License (Ms-PL)
 * http://opensource.org/licenses/ms-pl
 * http://ozframework.codeplex.com/
 *************************************************************************/

namespace OhZeeCreative.Xna
{
    using System;
    using System.Windows;
    using System.Windows.Threading;
    using Microsoft.Xna.Framework;

    public class XnaDispatchTimer : IApplicationService
    {
        private DispatcherTimer frameworkDispatcherTimer;
        public XnaDispatchTimer()
        {
            this.frameworkDispatcherTimer = new DispatcherTimer();
            this.frameworkDispatcherTimer.Tick += new EventHandler(frameworkDispatcherTimer_Tick);
            this.frameworkDispatcherTimer.Interval = TimeSpan.FromMilliseconds(100.0/30.0);

            FrameworkDispatcher.Update();
        }
        void IApplicationService.StartService(ApplicationServiceContext context) { this.frameworkDispatcherTimer.Start(); }
        void IApplicationService.StopService() { this.frameworkDispatcherTimer.Stop(); }
        void frameworkDispatcherTimer_Tick(object sender, EventArgs e) { FrameworkDispatcher.Update(); }

    }
}
